#课后作业
#1.给定一个列表,根据grade来排序

classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]

classes.sort(key=lambda x : x["grade"])
print("1.根据grade排序的结果为:claseese=",classes)
print("--------分隔符------")


#2.通过filter语句来筛选出Grade为A的同学

f = filter(lambda x : x["grade"]=="A",classes)
a = list(f)

for i in a:
    print("2.Grade为A的同学有:",i["name"])
print("--------分隔符------")

#3.通过`map`函数将上述同学的`age` + 1(对原数据结构有影响, 尽量不要用lambda)

#3.1 试验用lambda:

m = map(lambda x : x["age"]+1,classes)
print(list(m))
print("--------分隔符------")
#3.2 尝试其他方法:

def add(a):
    return a + 1

b = []
for i in range(7):
	b.append(classes[i]["age"])
m = map(add,b)
print(list(m))
print("--------分隔符------")

#4.使用递归函数重构斐波那契函数

def fab(n):
	if n == 1:
		return 1
	if n == 0:
		return 0
	else:
		return fab(n-1)+fab(n-2)
for i in range(10):
	print(fab(i))